package com.gitee.feizns.explore.data_structure.array.easy;

/**
 * 53. 最大子序和
 * @author feizns
 * @since 2020/1/8
 */
public class MaxSubArray {

    public static void main(String[] args) {

    }

    public static int maxSubArray(int[] nus) {
        int ans = nus[0];
        int sum = 0;
        for (int i : nus) {
            if ( sum > 0 )
                sum += i;
            else
                sum = i;
            ans = Math.max(ans, sum);
        }
        return ans;
    }

}
